import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import { LoginPage } from '../login/login';
import { PersonDetailPage } from '../person-detail/person-detail';
import { BuildingsDataProvider } from '../../providers/buildings-data/buildings-data';
import { ActivePage } from '../active/active';
import { SetPage } from '../set/set';



@Component({
  selector: 'page-department-personal',
  templateUrl: 'department-personal.html',
})
export class DepartmentPersonalPage {

  cacheCount: number = 0;

  constructor(public navCtrl: NavController,
    public navParams: NavParams,
    public storage: Storage,
    public buildingsDataProvider: BuildingsDataProvider) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad DepartmentPersonalPage');
  }


  ionViewWillEnter() {
    this.buildingsDataProvider.getCacheCount().then(res => {
      if (res && res.rows && res.rows.length > 0) {
        this.cacheCount = res.rows.item(0).count as number;
      }
    }).catch(()=>{
      console.log("数据表访问错误");
    });
  }

  /**
   * 退出登录
   */
  logout() {
    this.storage.remove('USER_INFO');
    this.storage.remove('LOGIN_INFO');
    this.navCtrl.setRoot(LoginPage);
  }

  itemTapped(): void {
    this.navCtrl.push(PersonDetailPage);
  }

  itemActive():void{
    this.navCtrl.push(ActivePage);
  }

  itemSet():void{
    this.navCtrl.push(SetPage);
  }

}
